/*
 * Copyright (c) 2006 - 2022, webrx.cn All rights reserved.
 *
 */
package cn.demo;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;

/**
 * <p>Project: app2022 - IntSortDemo
 * <p>Powered by webrx On 2022-01-25 17:36:40
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class IntSortDemo {
    public static void main(String[] args) {
        Integer[] is = {1, 2, 30, 5, 40, 12, 99, 88, 6};
        System.out.println(Arrays.toString(is));

        //升序
        Arrays.sort(is, (a, b) -> a - b);
        Arrays.sort(is, Comparator.comparingInt(a -> a));
        System.out.println(Arrays.toString(is));

        //降序
        Arrays.sort(is, (a, b) -> b - a);
        System.out.println(Arrays.toString(is));

        //乱序
        Arrays.sort(is, (a, b) -> Math.random() < .5 ? -1 : 1);
        System.out.println(Arrays.toString(is));

        //乱序，数组 转换为 list 调用shuffle方法
        var list = new ArrayList(Arrays.stream(is).toList());
        Collections.shuffle(list);
        list.toArray(is);
        System.out.println(Arrays.toString(is));

    }
}
